<template>
  <el-container class="main_container"  >
    <!--头部-->
    <el-header>
      <div style="float: left;">
        <span style="margin-left:20px;">
          <img
            src="../assets/ilogo.png"
            width="250px;"
            style="margin-left:-10px;"
            height="100%;"
            alt
            srcset
          />
        </span>
      </div>
        <el-dropdown trigger="click" style="float: right;height: 55px;">
         <span class="el-dropdown-link">
            <img
              src="../assets/33.png"
              :src="user.avatar"
              width="55px"
              style="margin-left:-20px;margin-top: 3px;"
              height="100%;"
              alt
              srcset
            />
          </span>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item icon="el-icon-setting">&nbsp;系统首页</el-dropdown-item>
            <el-dropdown-item icon="el-icon-chat-round">&nbsp;交流谈论</el-dropdown-item>
            <el-dropdown-item icon="el-icon-switch-button">&nbsp;<el-button @click="getOutLogin()" >退出登录</el-button></el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
    </el-header>
    <!--中心部分-->
    <el-container>
      <el-aside  style="background-color: white;width: auto;" >
        <!--收缩按钮-->
        <div class="toggle-btn" @click="toggleMenu">|||</div>
        <!--侧面菜单栏-->
        <el-menu default-active="/welcome"
                 :router="true"
                 class="el-menu-vertical-demo"
                 @open="handleOpen"
                 @close="handleClose"
                 :collapse="isCollapse">
          <MenuTree :menuList="menuList"></MenuTree>
        </el-menu>
      </el-aside>
      <el-main  >
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>

</template>

<script>
  import MenuTree from "../views/MenuTree";
  import {outLogin} from "../api/user";

  export default {
    name: 'Main',
    data() {
      return {
        isCollapse: false,
        menuList: JSON.parse(window.sessionStorage.getItem("menuList")),
        user: JSON.parse(window.sessionStorage.getItem("user")),
      };
    },
    components:{
      MenuTree,
    },
    methods: {
      handleOpen(key, keyPath) {
       /* console.log(key, keyPath);*/
      },
      handleClose(key, keyPath) {
       /* console.log(key, keyPath);*/
      },
      toggleMenu:function () {
        this.isCollapse=!this.isCollapse;
      },
      getOutLogin:function () {
        var $this=this;
        outLogin()
          .then(function (response) {
            console.log(response.data);
            window.sessionStorage.removeItem("user");
            window.sessionStorage.removeItem("menuList");
            $this.$router.push("/");
          })
          .catch(function (erro) {
            console.log("请求失败！");
          })
      }

    },created :function () {
        /*this.menuList=this.$route.params.tbMenus;*/
        /*console.log(window.sessionStorage.getItem("user"));*/
        this.$router.push("/welcome");
    }
  }
</script>

<style land="less" scoped>

  .main_container{
    width: 100%;
    height: 100% !important;
  }

  .el-header {
    background-color: #B3C0D1;
    color: #333;
    text-align: center;
    line-height: 60px;


  }

  .el-aside {
    background-color: #D3DCE6;
    /*color: #333;
    text-align: center;*/

  }

  .el-main {
    background-color: #E9EEF3;
    /*color: #333;
    text-align: center;
    line-height: 160px;*/
  }

  body > .el-container {
    margin-bottom: 40px;
  }

  .el-container:nth-child(5) .el-aside,
  .el-container:nth-child(6) .el-aside {
    line-height: 260px;
  }

  .el-container:nth-child(7) .el-aside {
    line-height: 320px;
  }

  .el-dropdown-link {
    cursor: pointer;
    color: #409EFF;
  }
  .el-icon-arrow-down {
    font-size: 12px;
  }
  .demonstration {
    display: block;
    color: #8492a6;
    font-size: 14px;
    margin-bottom: 20px;
  }
  .el-menu-vertical-demo:not(.el-menu--collapse) {
    width: 200px;
    min-height: 400px;
  }
  .toggle-btn {
    background-color: rebeccapurple;
    font-size: 10px;
    line-height: 24px;
    color: #fff;
    text-align: center;
    letter-spacing: 0.2em;
    cursor: pointer;
  }
</style>
